import TabMenu from "./data";
Component({
  data: {
    active: 0,
    list: TabMenu,
  },

  methods: {
    onChange(event) {
      const activeIndex = event.detail.value;
      console.log("onChange tab", activeIndex);
      this.setData({ active: activeIndex });
      const url = this.data.list[activeIndex].url;
      console.log("url", url);
      wx.switchTab({
        url: url.startsWith("/") ? url : `/${url}`,
      });
    },

    init() {
      const page = getCurrentPages().pop();
      const route = page ? page.route.split("?")[0] : "";
      const active = this.data.list.findIndex(
        (item) =>
          (item.url.startsWith("/") ? item.url.substr(1) : item.url) ===
          `${route}`
      );
      this.setData({ active });
    },
  },
});
